package com.quanyan.user.web;

import com.quanyan.api.APIResponse;
import com.quanyan.user.model.vo.request.ReqUnReadNews;
import com.quanyan.user.service.NewsUnReadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/3/8.
 */
@RestController
@RequestMapping("/api/user/unReadNews")
public class NewsUnReadController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(NewsUnReadController.class);

    @Autowired
    private NewsUnReadService newsUnReadService;


    @RequestMapping("/count")
    public APIResponse queryUnReadCount(@RequestBody ReqUnReadNews reqUnReadNews ,HttpServletRequest request){
        try {
            Integer uid =(Integer) request.getAttribute("uid");
            reqUnReadNews.setUid(uid);
            return APIResponse.returnSuccess(newsUnReadService.queryUnReadNewsCount(uid));
        } catch (Exception e) {
            logger.error("{}",e);
            return APIResponse.returnFail("系统异常！");
        }
    }



    @RequestMapping("/list")
    public APIResponse query(@RequestBody ReqUnReadNews reqUnReadNews ,HttpServletRequest request){
        try {
            Integer uid =(Integer) request.getAttribute("uid");
            reqUnReadNews.setUid(uid);
            return APIResponse.returnSuccess(newsUnReadService.queryUnReadNews(reqUnReadNews));
        } catch (Exception e) {
            logger.error("{}",e);
            return APIResponse.returnFail("系统异常！");
        }
    }

}
